package com.faker.controller;

import com.faker.core.dto.ResponseResult;
import com.faker.core.jdbc.DataSourceChange;
import com.faker.entity.SysConfiguration;
import com.faker.entity.SysConnection;
import com.faker.service.ConfigurationService;
import com.faker.service.DataGenerateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 生成配置 控制器
 */
@RestController
@RequestMapping(value = "configuration")
@Slf4j
public class ConfigurationController {
    @Resource
    private ConfigurationService configurationService;

    /**
     * 保存生成配置
     *
     * @param sysConfiguration
     * @return
     */
    @PostMapping(value = "/saveConfiguration")
    public ResponseResult saveConfiguration(@RequestBody SysConfiguration sysConfiguration) {
        DataSourceChange.changeDataSource();
        int count = configurationService.saveConfiguration(sysConfiguration);
        return ResponseResult.success(count);
    }


    /**
     * 查询生成配置
     *
     * @param connectionId
     * @return
     */
    @GetMapping(value = "/queryConfiguration")
    public ResponseResult queryConfiguration(@RequestParam(name = "connectionId") Long connectionId) {
        DataSourceChange.changeDataSource();
        SysConfiguration sysConfiguration = configurationService.queryConfiguration(connectionId);
        return ResponseResult.success(sysConfiguration);

    }


}
